// miniprogram/pages/map/map.js
const db = wx.cloud.database();
const mapCollection = db.collection('sweet');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mapHidden:true,
    activeSwiperIndex:0,
    activeTabIndex: 0,
    boolean:true,
    map:[],
    latitude:"28.72451",
    longitude:"115.834968",
    markers:[
      {
        id: 0,
        iconPath: "../../images/map.png",
        latitude: 28.718153,
        longitude:115.827033,
        width: 50,  
        height: 50,  
        title:"蜜雪冰城(东华理工大学)"
      },
      {
        id: 1,
        iconPath: "../../images/map.png",
        latitude: 28.726115,
        longitude:115.837033,
        width: 50,  
        height: 50,  
        title:"蜜雪冰城(理工学院店)"
      },
      {
        id: 2,
        iconPath: "../../images/map.png",
        latitude: 28.725615,
        longitude:115.827033,
        width: 50,  
        height: 50,  
        title:"蜜雪冰城(理工学院店)"
      },
      {
        id: 3,
        iconPath: "../../images/map.png",
        latitude: 28.715115,
        longitude:115.817033,
        width: 50,  
        height: 50,  
        title:"蜜雪冰城(理工学院店)"
      },
      {
        id: 4,
        iconPath: "../../images/map.png",
        latitude: 28.726315,
        longitude:115.817033,
        width: 50,  
        height: 50,  
        title:"蜜雪冰城(理工学院店)"
      },
      {
        id: 5,
        iconPath: "../../images/map.png",
        latitude: 28.708115,
        longitude:115.827033,
        width: 50,  
        height: 50,  
        title:"蜜雪冰城(理工学院店)"
      }
    ]
  },
  onShareAppMessage(){
    return{
      title:'蜜雪冰城',
      imageUrl:'https://picture.sandload.cn/1625905903984.gif',
      path:'pages/index/index'
    }
  },
  switchTab(e){
    // let shops = e.currentTarget.dataset.shops;
    let index = e.currentTarget.dataset.index;
    if(index == this.data.activeTabIndex){
      return 0;
    }
    this.setData({
      activeTabIndex:index,
      activeSwiperIndex:index
    })
  },
  collection(event){
    wx.navigateTo({
      url: `../collection/collection?id=${event.target.dataset.id}`
    })
  },
  goOrder(event){
    wx.switchTab({
      url: '../order/order'
    })
  },
  gotoIndex(event){
    wx.switchTab({
      url: '../index/index'
    })
  },
  Event(e){
    // console.log(e)
    // var bol = this.data.boolean;
    this.setData({
      mapHidden:!this.data.mapHidden,
      boolean:!this.data.boolean
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(res) {
    const {data} = await mapCollection.get();
    console.log(data);
    this.setData({
      map:data
    })
    this.setData({
      latitude: res.latitude,
      longitude: res.longitude,
      markers: [{
        latitude: res.latitude,
        longitude: res.longitude
      }]
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})